<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>quick-cocos2d-x API Documents - framework.client.api.Store</title>
<link rel="stylesheet" href="luadocx-style.css" type="text/css" />
<link rel="stylesheet" href="luadocx-style-monokai.css" type="text/css" />
<script src="luadocx-highlight.min.js"></script>
<script type="text/javascript" charset="utf-8">hljs.initHighlightingOnLoad();</script>
</head>
<body>
  <div id="container">

    <table id="main">
      <tr>
        <td id="navigation">

          <h2>Links</h2>
          <ul>
            <li><a href="index.html">Index</a></li>
          </ul>

          <h2>Modules</h2>
          <ul>
            <li><a href="index.html">framework.init</a></li>
            <li><a href="framework.client.api.context.html">framework.client.api.Context</a></li>
            <li><a href="framework.client.api.eventprotocol.html">framework.client.api.EventProtocol</a></li>
            <li><a href="framework.client.api.gamenetwork.html">framework.client.api.GameNetwork</a></li>
            <li><a href="framework.client.api.gamestate.html">framework.client.api.GameState</a></li>
            <li><a href="framework.client.api.localize.html">framework.client.api.Localize</a></li>
            <li><strong>framework.client.api.Store</strong></li>
            <li><a href="framework.client.api.timer.html">framework.client.api.Timer</a></li>
            <li><a href="framework.client.api.gamenetwork.openfeint.html">framework.client.api.gamenetwork.OpenFeint</a></li>
            <li><a href="framework.client.audio.html">framework.client.audio</a></li>
            <li><a href="framework.client.crypto.html">framework.client.crypto</a></li>
            <li><a href="framework.client.device.html">framework.client.device</a></li>
            <li><a href="framework.client.display.html">framework.client.display</a></li>
            <li><a href="framework.client.init.html">framework.client.init</a></li>
            <li><a href="framework.client.luaj.html">framework.client.luaj</a></li>
            <li><a href="framework.client.luaoc.html">framework.client.luaoc</a></li>
            <li><a href="framework.client.network.html">framework.client.network</a></li>
            <li><a href="framework.client.scheduler.html">framework.client.scheduler</a></li>
            <li><a href="framework.client.transition.html">framework.client.transition</a></li>
            <li><a href="framework.client.ui.html">framework.client.ui</a></li>
            <li><a href="framework.server.mysqleasy.html">framework.server.MysqlEasy</a></li>
            <li><a href="framework.server.rediseasy.html">framework.server.RedisEasy</a></li>
            <li><a href="framework.server.serveraction.html">framework.server.ServerAction</a></li>
            <li><a href="framework.server.serverapp.html">framework.server.ServerApp</a></li>
            <li><a href="framework.server.session.html">framework.server.Session</a></li>
            <li><a href="framework.server.init.html">framework.server.init</a></li>
            <li><a href="framework.shared.modelbase.html">framework.shared.ModelBase</a></li>
            <li><a href="framework.shared.debug.html">framework.shared.debug</a></li>
            <li><a href="framework.shared.errors.html">framework.shared.errors</a></li>
            <li><a href="framework.shared.functions.html">framework.shared.functions</a></li>
          </ul>

        </td> <!-- navigation -->

        <td id="content">

          <h1>Module <code>framework.client.api.Store</code></h1>

          <!-- BEGIN module doc -->

          <div id="module_doc">

<p>This feature allows you to support In-App Purchases. Currently, only the Apple iTunes Store is supported. In the future, other store fronts may be added.</p>

<p>@module framework.client.api.Store</p>

<br />


          </div>

          <!-- END module doc -->


          <!--  BEGIN functions index -->

          <h2>Functions</h2>
          <table class="function_list">


            <tr>
              <td class="name" nowrap><a href="#anchor_Store_init">Store.init&nbsp;(listener)</a></td>
              <td class="summary">Activates In-App Purchases.</td>
            </tr>


            <tr>
              <td class="name" nowrap><a href="#anchor_Store_getReceiptVerifyMode">Store.getReceiptVerifyMode&nbsp;()</a></td>
              <td class="summary"></td>
            </tr>


            <tr>
              <td class="name" nowrap><a href="#anchor_Store_setReceiptVerifyMode">Store.setReceiptVerifyMode&nbsp;(mode,&nbsp;isSandbox)</a></td>
              <td class="summary"></td>
            </tr>


            <tr>
              <td class="name" nowrap><a href="#anchor_Store_getReceiptVerifyServerUrl">Store.getReceiptVerifyServerUrl&nbsp;()</a></td>
              <td class="summary"></td>
            </tr>


            <tr>
              <td class="name" nowrap><a href="#anchor_Store_setReceiptVerifyServerUrl">Store.setReceiptVerifyServerUrl&nbsp;(url)</a></td>
              <td class="summary"></td>
            </tr>


            <tr>
              <td class="name" nowrap><a href="#anchor_Store_canMakePurchases">Store.canMakePurchases&nbsp;()</a></td>
              <td class="summary">Returns true if purchases are allowed, false otherwise.</td>
            </tr>


            <tr>
              <td class="name" nowrap><a href="#anchor_Store_loadProducts">Store.loadProducts&nbsp;(productsId,&nbsp;listener)</a></td>
              <td class="summary">Retrieves information about items available for sale.</td>
            </tr>


            <tr>
              <td class="name" nowrap><a href="#anchor_Store_cancelLoadProducts">Store.cancelLoadProducts&nbsp;()</a></td>
              <td class="summary"></td>
            </tr>


            <tr>
              <td class="name" nowrap><a href="#anchor_Store_isProductLoaded">Store.isProductLoaded&nbsp;(productId)</a></td>
              <td class="summary"></td>
            </tr>


            <tr>
              <td class="name" nowrap><a href="#anchor_Store_purchase">Store.purchase&nbsp;(productId)</a></td>
              <td class="summary">Initiates a purchase transaction on a provided list of products.</td>
            </tr>


            <tr>
              <td class="name" nowrap><a href="#anchor_Store_finishTransaction">Store.finishTransaction&nbsp;(transaction)</a></td>
              <td class="summary">Notifies the App Store that a transaction is complete.</td>
            </tr>


          </table>

          <!--  END functions index -->

          <br />
          <br />

          <!-- BEGIN functions details -->

          <h2>Functions</h2>
          <dl class="function">


            <dt class="">
              <a name="anchor_Store_init"></a>
              <h3>Store.init (listener)</h3>
            </dt>

            <dd class="">

<p>Activates In-App Purchases.</p>

<p>Starts up the In-App Purchase engine and allows you to receive callbacks with the listener function you specify.</p>

<p><strong>Syntax:</strong></p>


<pre><code class="lua">framework.client.api.Store.init(listener)
</code></pre>

<p><strong>Example:</strong></p>


<pre><code class="lua">function transactionCallback(event)
    local transaction = event.transaction
    if transaction.state == "purchased" then
        print("Transaction succuessful!")
        print("productId", transaction.productId)
        print("quantity", transaction.quantity)
        print("transactionIdentifier", transaction.transactionIdentifier)
        print("date", os.date("%Y-%m-%d %H:%M:%S", transaction.date))
        print("receipt", transaction.receipt)
    elseif  transaction.state == "restored" then
        print("Transaction restored (from previous session)")
        print("productId", transaction.productId)
        print("receipt", transaction.receipt)
        print("transactionIdentifier", transaction.identifier)
        print("date", transaction.date)
        print("originalReceipt", transaction.originalReceipt)
        print("originalTransactionIdentifier", transaction.originalIdentifier)
        print("originalDate", transaction.originalDate)
    elseif transaction.state == "failed" then
        print("Transaction failed")
        print("errorCode", transaction.errorCode)
        print("errorString", transaction.errorString)
    else
        print("unknown event")
    end

    -- Once we are done with a transaction, call this to tell the store
    -- we are done with the transaction.
    -- If you are providing downloadable content, wait to call this until
    -- after the download completes.
    framework.client.api.Store.finishTransaction(transaction)
end

framework.client.api.Store.init(transactionCallback)
</code></pre>

<p><br /></p>

<p>@tparam function listener
This is the listener that will handle transaction callback events.</p>

<p>@return Nothing.</p>

            </dd>


            <dt class="">
              <a name="anchor_Store_getReceiptVerifyMode"></a>
              <h3>Store.getReceiptVerifyMode ()</h3>
            </dt>

            <dd class="">



            </dd>


            <dt class="">
              <a name="anchor_Store_setReceiptVerifyMode"></a>
              <h3>Store.setReceiptVerifyMode (mode, isSandbox)</h3>
            </dt>

            <dd class="">



            </dd>


            <dt class="">
              <a name="anchor_Store_getReceiptVerifyServerUrl"></a>
              <h3>Store.getReceiptVerifyServerUrl ()</h3>
            </dt>

            <dd class="">



            </dd>


            <dt class="">
              <a name="anchor_Store_setReceiptVerifyServerUrl"></a>
              <h3>Store.setReceiptVerifyServerUrl (url)</h3>
            </dt>

            <dd class="">



            </dd>


            <dt class="">
              <a name="anchor_Store_canMakePurchases"></a>
              <h3>Store.canMakePurchases ()</h3>
            </dt>

            <dd class="">

<p>Returns true if purchases are allowed, false otherwise.</p>

<p><strong>Syntax:</strong></p>


<pre><code class="lua">value = framework.client.api.Store.canMakePurchases
</code></pre>

<p><strong>Example:</strong></p>


<pre><code class="lua">if framework.client.api.Store.canMakePurchases() then
    framework.client.api.Store.purchase(productId)
else
    print("Store purchases are not available")
end
</code></pre>

<p><strong>Note:</strong></p>

<p>iOS devices have a setting that disables purchasing. A common case for this is to prevent children from accidentally purchasing things without parents' permission. Corona provides an API to check whether purchasing is possible. Use this preemptively to avoid having your users navigate through many purchase steps only to find out at the last step that purchasing is forbidden.</p>

<p><br /></p>

<p>@return Returns true if purchases are allowed, false otherwise.</p>

            </dd>


            <dt class="">
              <a name="anchor_Store_loadProducts"></a>
              <h3>Store.loadProducts (productsId, listener)</h3>
            </dt>

            <dd class="">

<p>Retrieves information about items available for sale.
This includes the price of each item, a localized name, and a localized description.</p>

<p><strong>Syntax:</strong></p>


<pre><code class="lua">framework.client.api.Store.loadProducts(arrayOfProductIdentifiers, listener)
</code></pre>

<p><strong>Example:</strong></p>


<pre><code class="lua">function productCallback(event)
    print("showing valid products", #event.products)
    for i=1, #event.products do
        print(event.products[i].title)              -- string.
        print(event.products[i].description)        -- string.
        print(event.products[i].price)              -- number.
        print(event.products[i].localizedPrice)     -- string.
        print(event.products[i].productIdentifier)  -- string.
    end

    print("showing invalidProducts", #event.invalidProducts)
    for i=1, #event.invalidProducts do
        print(event.invalidProducts[i])
    end
end

local productsId = {
    "com.anscamobile.NewExampleInAppPurchase.ConsumableTier1",
    "com.anscamobile.NewExampleInAppPurchase.NonConsumableTier1",
    "com.anscamobile.NewExampleInAppPurchase.SubscriptionTier1",
    -- "bad.product.id",
}

framework.client.api.Store.loadProducts(productsId, productCallback)
</code></pre>

<p><br /></p>

<p>@tparam table productsId
A Lua array with each element containing a string which is the product identifier of the in-app item you want to know about.</p>

<p>@tparam function listener
A callback function that is invoked when the store finishes retrieving the product information.</p>

<p>@return Nothing.</p>

            </dd>


            <dt class="">
              <a name="anchor_Store_cancelLoadProducts"></a>
              <h3>Store.cancelLoadProducts ()</h3>
            </dt>

            <dd class="">



            </dd>


            <dt class="">
              <a name="anchor_Store_isProductLoaded"></a>
              <h3>Store.isProductLoaded (productId)</h3>
            </dt>

            <dd class="">



            </dd>


            <dt class="">
              <a name="anchor_Store_purchase"></a>
              <h3>Store.purchase (productId)</h3>
            </dt>

            <dd class="">

<p>Initiates a purchase transaction on a provided list of products.</p>

<p>This function will send out purchase requests to the store. The listener you specified in framework.client.api.Store.init() will be invoked when the store finishes processing the transaction.</p>

<p><strong>Syntax:</strong></p>


<pre><code class="lua">framework.client.api.Store.purchase(productId)
</code></pre>

<p><strong>Example:</strong></p>


<pre><code class="lua">framework.client.api.Store.purchase("com.framework.example.ConsumableTier1")
</code></pre>

<p><br /></p>

<p>@param productId
A string which is the product identifier string.</p>

<p>@return Nothing.</p>

            </dd>


            <dt class="">
              <a name="anchor_Store_finishTransaction"></a>
              <h3>Store.finishTransaction (transaction)</h3>
            </dt>

            <dd class="">

<p>Notifies the App Store that a transaction is complete.</p>

<p>After you finish handling a transaction, you must call framework.client.api.Store.finishTransaction() on the transaction object. If you don't do this, the App Store will think your transaction was interrupted and will attempt to resume it on the next application launch.</p>

<p><strong>Syntax:</strong></p>


<pre><code class="lua">framework.client.api.Store.finishTransaction(transaction)
</code></pre>

<p>@tparam table transaction
The transaction object belonging to the transaction you want to mark as finished.</p>

<p>@return Nothing.</p>

            </dd>


          </dl>

          <!-- BEGIN functions details -->


      </td> <!-- id="content" -->

      </tr>
    </table> <!-- id="main" -->

    <div id="about">
      <i>update: 2013-05-08 09:30:25, generated by <a href="http://github.com/dualface/luadocx">luadocx 1.1</a></i>
    </div> <!-- id="about" -->

  </div> <!-- id="container" -->

</body>
</html>
